package com.ideal.view.action;
import com.ideal.view.component.TableComponent;
import com.intellij.ide.CopyProvider;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import com.intellij.ui.content.ContentManager;

/**
 * 代码生成Action
 * @author mx
 */
public class CodeGenerateAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        Application application = ApplicationManager.getApplication();
        DataContext dataContext = e.getDataContext();
        String path = getAbsolutePath(dataContext);
        TableComponent tableComponent = application.getComponent(TableComponent.class);
        tableComponent.showTable(path);
    }


    /**
     * 获得当前选择文件夹的路径
     */
    private static String getAbsolutePath(DataContext dataContext){
        VirtualFile file = DataKeys.VIRTUAL_FILE.getData(dataContext);
        if(file.isDirectory()){
            return file.getPath();
        }else {
            return null;
        }
    }

}
